#include "qtimeediteditor.h"

#include "../../shared/property/qabstractproperty.h"
#include "../../shared/qpropertyfactory.h"

QTimeEditEditor::QTimeEditEditor(QAbstractProperty *pro,QUndoStack* , QWidget *parent):
    QTimeEdit(parent),
    m_property(pro)
{
    setTime(pro->get_value().toTime());
    connect(this,SIGNAL(timeChanged(QTime)),this,SLOT(value_changed()));
    connect(m_property,SIGNAL(refresh()),this,SLOT(property_changed()));
}

void QTimeEditEditor::value_changed()
{
    m_property->emit_edit_value(time());
}

void QTimeEditEditor::property_changed()
{
    setTime(m_property->get_value().toTime());
}



QDateEditEditor::QDateEditEditor(QAbstractProperty *pro,QUndoStack* , QWidget *parent):
    QDateEdit(parent),
    m_property(pro)
{
    setDate(pro->get_value().toDate());
    connect(this,SIGNAL(dateChanged(QDate)),this,SLOT(value_changed()));
    connect(m_property,SIGNAL(refresh()),this,SLOT(property_changed()));
}

void QDateEditEditor::value_changed()
{
    m_property->emit_edit_value(date());
}

void QDateEditEditor::property_changed()
{
    setDate(m_property->get_value().toDate());
}




QDateTimeEditEditor::QDateTimeEditEditor(QAbstractProperty *pro,QUndoStack* , QWidget *parent):
    QDateTimeEdit(parent),
    m_property(pro)
{
    setDateTime(pro->get_value().toDateTime());
    connect(this,SIGNAL(dateTimeChanged(QDateTime)),this,SLOT(value_changed()));
    connect(m_property,SIGNAL(refresh()),this,SLOT(property_changed()));
}

void QDateTimeEditEditor::value_changed()
{
    m_property->emit_edit_value(dateTime());
}

void QDateTimeEditEditor::property_changed()
{
    setDateTime(m_property->get_value().toDateTime());
}

qRegisterPropertyEditor(Time,QTimeEditEditor)
qRegisterPropertyEditor(Date,QDateEditEditor)
qRegisterPropertyEditor(DateTime,QDateTimeEditEditor)
